function chooseAll(){
    var choose = document.getElementsByClassName("delete")
    var all = document.getElementById("chooseAll").checked
    if(all){
        for(let i=0;i<choose.length;i++){
            choose[i].checked = true
        }
    }else{
        for(let i=0;i<choose.length;i++){
            choose[i].checked = false
        }
    }
}
function allChoose(){
    var choose = document.getElementsByClassName("delete")
    var all = document.getElementById("chooseAll")
    var a=0
    for(i=0;i<choose.length;i++){
        if(choose[i].checked){
            a++
        }
    }
    if(a == choose.length){
        all.checked = true
    }else{
        all.checked = false
    }
}
function footMark(){
    axios.get('/home/footmark/browse/queryAllBrose',{
        params:{
        }
    }).then(function(data){
        if(data.data.data.code==20000){
            var list = data.data.data.data
            if(list == null){
                document.getElementById("myMessage").innerHTML = ``
                document.getElementById("myMessage").innerHTML += `
                <div class="nothing">足迹里什么也没有哦，赶紧去浏览添加吧</div>
                `
            }else{
                document.getElementById("myMessage").innerHTML = `
                <div class="order">我的足迹</div>
                <div class="operation">
                    <input type="checkbox" id="chooseAll" onchange="chooseAll()">全选
                    <button onclick="chooseDelete()">删除</button>
                </div>
                `
                for(let i = 0;i<list.length;i++){
                    document.getElementById("myMessage").innerHTML += `
                    <div class="orderbox">
                        <div class="choose">                            
                            <input type="checkbox" class="delete" onchange="allChoose();addInDelete(${list[i].browseId})">
                        </div>
                        <div class="orderMessage">
                            <div class="goodPhoto"><img src="${list[i].imagePath}"></div>
                            <div class="goodMessage">
                                <div class="title">${list[i].goodsName}</div>
                                <p class="size">${list[i].size}</p>
                            </div>
                            <div class="price">
                                <p>浏览日期:&nbsp&nbsp&nbsp${list[i].browseTime}</p>
                            </div>
                        </div>
                    </div>
                    `
                }
            }
        }else{
            document.getElementById("floatContent").innerHTML ="<div>"+ "很抱歉"+"</div>"+"<div>"+"地址检索失败，请联系工作人员"+"</div>"+"<button onclick='closethis()' class='newbtn'>"+"确定"+"</button>";
            document.getElementById("floatContent").classList.remove("hide");
        }
    }).catch(function (error){
        console.log(error)
        document.getElementById("floatContent").innerHTML ="<div>"+ "很抱歉"+"</div>"+"<div>"+"请检查网络情况"+"</div>"+"<button onclick='closethis()' class='newbtn'>"+"确定"+"</button>";
        document.getElementById("floatContent").classList.remove("hide");
    })
}
var readyDelete = new Array();
function addInDelete(a){
    var browseId = a
    console.log(browseId)
    if(readyDelete.indexOf(browseId)>-1){ //查找id是否已经存在于数组中
        // console.log(readyDelete)
        // console.log(readyDelete[0])
        for(let i=0;i<readyDelete.length;i++){
            if(readyDelete[i] == browseId){
                readyDelete.splice(i,1)
            }
        }
    }else{
        // console.log(readyDelete)
        readyDelete.push(browseId)
        readyDelete.map(Number)     //以一个新数组的形式返回
        console.log(readyDelete)
    }
}
function chooseDelete(){
    console.log(readyDelete[0])
    browseId = readyDelete.map(Number)
    console.log(browseId)
    axios.delete('/home/footmark/browse/deleteSomeBrowse',{
        params:{
            browseId:readyDelete
        }
    }).then(function(data){
        console.log(data.data.data)
        if(data.data.data.code==20000){
            document.getElementById("floatContent").innerHTML ="<div>"+"删除足迹成功"+"</div>"+"<button onclick='closethis()' class='newbtn'>"+"确定"+"</button>";
            document.getElementById("floatContent").classList.remove("hide");
        }else{
            document.getElementById("floatContent").innerHTML =`<div>很抱歉</div><div>${data.data.data.data}</div><button onclick='closethis()' class='newbtn'>确定</button>`;
            document.getElementById("floatContent").classList.remove("hide");
        }
    }).catch(function (error){
        console.log(error);
        document.getElementById("floatContent").innerHTML ="<div>"+ "很抱歉"+"</div>"+"<div>"+"请检查网络情况"+"</div>"+"<button onclick='closethis()' class='newbtn'>"+"确定"+"</button>";
        document.getElementById("floatContent").classList.remove("hide");
    })
}
window.onload = function(){
    (function(){footMark()})();
}
function  closethis(){
    document.getElementById("floatContent").classList.add("hide");
}